package com.player.thirdGroup.controller;

import com.player.thirdGroup.entity.Role;
import com.player.thirdGroup.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

/**
 * @ClassName RoleController
 * @Description: TODO
 * @Author ForeverLoveT
 * @Date 2019/12/29 19:32
 * @Version V1.0
 **/
@Controller
public class RoleController {
    @Autowired
    private RoleService roleService;
    @GetMapping("rolehtml")
    public String rolehtml(){
        return "role";
    }

    @GetMapping("rolelist")
    @ResponseBody
    public List<Role> findAll(Model model){
        List<Role> all = roleService.findAll();
       return all;
    }
    //修改
    @GetMapping("showid")
    @ResponseBody
    public Role findByid(String roleid){
        Role byid = roleService.findByid(roleid);
        System.err.println(byid);
        return byid;
    }
    //禁用and启用
    @GetMapping("jyAndqy")
    @ResponseBody
    public String jinAndqi(String roleid,String rolestatus){
        roleService.updateStatus(roleid,rolestatus);
        return "修改状态成功";
    }
    @PostMapping("roleadd")
    @ResponseBody
    public String roleAdd(Role role){
        role.setRoledate(new Date());
        System.err.println(role);
        roleService.roleAdd(role);
        return "添加成功";
    }
    //修改
    /** 
     * @MethodName: update
     * @Description: TODO
     * @Param: []
     * @Return: java.lang.String
     * @Author: ForeverLoveT
     * @Date: 8:31
    **/
    @PostMapping("update")
    @ResponseBody
    public String update(Role role){
        System.err.println(role);
        role.setRoledate(new Date());
        roleService.update(role);
        return "修改成功";
    }
} 
